package com.example.system;

import com.example.mqtt.service.MqttService;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication(scanBasePackages = {
        "com.example.system",
        "com.example.security",
        "com.example.common",
        "com.example.mqtt"
})
public class SystemApplication implements CommandLineRunner {
    @Autowired
    private MqttService mqttService;
    public static void main(String[] args) {
        SpringApplication.run(SystemApplication.class, args);
    }
    @Override
    public void run(String... args) {
        // 订阅系统主题
        try {
            mqttService.subscribe("device/status");
        } catch (MqttException e) {
            e.printStackTrace();
        }
    }
}